<?php
/**
 * Controller_Helper
 *  
 * @author 王志昂
 * @version 
 */
class Controller_Helper extends Zend_Controller_Action
{
    protected $_validator;
    
    protected $_page;
    
    protected $_num;
    
    protected $_orderby;
    
    protected $_author;
    
    protected $_date;
    
    protected $_tag;
    
    public function init()
    {
        parent::init();
        $this->_validator = new Zend_Validate_Int();
        $this->_page = (int)$this->_request->getParam('page', 1);
        $this->_author = (int)$this->_request->getParam('author');
        $this->_date = $this->_request->getParam('date');
        $this->_tag = $this->_request->getParam('tag');
        $this->_orderby = Zend_Registry::get('config')->page->orderby;
        if (!$this->_validator->isValid($this->_page)) {
            $this->_page = 1;
        }
    }
    
    protected function _getArticleList($classType)
    {
        $type = Zend_Registry::get('config')->menu->$classType;
        
        if ($type == Zend_Registry::get('config')->menu->video) {
            $this->_num = Zend_Registry::get('config')->videopage->number;
        } else {
            $this->_num = Zend_Registry::get('config')->page->number;
        }
        
        $articleAmount = Business_Article::getInstance()->getArticleAmount(
            $type, 
            $this->_author,
            $this->_date,
            $this->_tag
        );
        $articleList = Business_Article::getInstance()->getArticleList(
            $type,
            $this->_page,
            $this->_num,
            $this->_orderby,
            $this->_author,
            $this->_date,
            $this->_tag
        );
        
        $this->view->type = $type;
        $this->view->page = $this->_page;
        $this->view->articleAmount = $articleAmount;
        $this->view->articleList = $articleList;
        $this->view->author = $this->_author;
        $this->view->date = $this->_date;
        
        $this->_getArticleMonth();
        
        return $articleList; //返回值给video使用，其他的不使用。
    }
    
    /**
     * 获取标题、控制器、面包屑等特殊内容
     * @param unknown $classType
     */
    protected function _getSpecialInfo($classType)
    {
        $this->view->title = Zend_Registry::get('config')->type->$classType->title;
        $this->view->controller = $classType;
        $this->view->breadcrumb = 'iLOVE&nbsp;&nbsp;' . strtoupper($classType);
    }
    
    /**
     * 获取边栏小插件
     */
    protected function _getWidgets()
    {
        $this->_getMostView();
        $this->_getArticleMonth();
        $this->_getTagsCloud();
    }
    
    /**
     * 获取查看更多
     */
    protected function _getMostView()
    {
        $this->view->mostviewed = Business_MostViewed::getInstance()->getAll();
    }
    
    /**
     * 获取按月显示
     */
    protected function _getArticleMonth()
    {
        $this->view->articleMonth = Business_Article::getInstance()->getAllArticleMonth();
    }
    
    /**
     * 获取标签云
     */
    protected function _getTagsCloud()
    {
        $tags = Business_Tags::getInstance()->getAllTagsWithCount();
        $this->view->tagsCloud = Business_Tags::getInstance()->formatTagsCloud($tags);
    }
}
